<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="../vue.global.js"></script>
  <title>Document</title>
</head>
<body>
  <div id="root">
    {{data.title}}
    {{count.x}}
  </div>
  <script type="module">
    const { createApp, reactive, ref, onMounted, watchEffect, watch } = window.Vue
    
    const app = createApp({
      setup() {
        const data = reactive({
          title: 'hello'
        })

        const count = ref(100)

        // 定义单独的钩子函数的目的是：有利于hooks的封装
        onMounted(() => {
          data.title = 'world'
          // console.log(count.value.x)
        })

        // const stop = watchEffect((onInvalidate) => {
        //   console.log(data.title)

        //   onInvalidate(() => {
        //     console.log(0)
        //   })
        // })

        // setTimeout(() => {
        //   stop()
        // }, 3000)

        // watchEffect(
        //   () => {
        //     console.log(data.title)
        //   },
        //   {
        //     onTrack() {
        //       console.log('ontracked.')
        //     },
        //     onTrigger() {
        //       console.log('onTrigger')
        //     }
        //   }
        // )

        watch(
          [
            () => {
              return data.title
            },
            () => {
              return count
            }
          ],
          ([newValue, newValue2], [oldValue, oldValue2]) => {
            console.log(newValue, oldValue)
            console.log(newValue2.value, oldValue2.value)
          }
        )

        return {
          data, 
          count
        }
      }
    })

    let vm = app.mount('#root')
  </script>
</body>
</html>